//
//  MIDImusicViewCell.m
//  迷笛
//
//  Created by . on 2018/9/10.
//  Copyright © 2018年 🍃🌺🌺🍃. All rights reserved.
//

#import "MIDImusicViewCell.h"

@implementation MIDImusicViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self addSubview:self.song];
        [self.song mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(WidthScale(13));
            make.left.mas_equalTo(WidthScale(46));
            [self.song setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        }];
        [self addSubview:self.singer];
        [self.singer mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.song.mas_bottom).offset(WidthScale(5));
            make.left.equalTo(self.song);
             [self.singer setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        }];
        [self addSubview:self.play];
        [self.play mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self.song.mas_right).offset(WidthScale(190));
            make.width.mas_offset(WidthScale(20));
            make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(20):HeightScale(20));
        }];
        
        [self addSubview:self.remove];
        [self.remove mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self.play.mas_right).offset(WidthScale(20));
            make.width.mas_offset(WidthScale(20));
            make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(20):HeightScale(20));
        }];
        
    }
    return self;
}
-(UILabel *)song
{
    if (!_song)
    {
        _song = [[UILabel alloc]init];
        _song.font =[UIFont systemFontOfSize:WidthScale(16)];
        _song.textColor = [UIColor whiteColor];
    }
    return _song;
}
-(UILabel *)singer
{
    if (!_singer)
    {
        _singer = [[UILabel alloc]init];
        _singer.font =[UIFont systemFontOfSize:WidthScale(14)];
        _singer.textColor = [UIColor colorWithHexString:@"#666666"];
    }
    return _singer;
}
-(UIButton *)play
{
    if (!_play)
    {
        _play =[[UIButton alloc]init];
        [_play setBackgroundImage:[UIImage imageNamed:@"play"] forState:0];
        [_play addTarget:self action:@selector(playBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _play;
}
-(void)playBtn:(UIButton * )sender
{
    sender.selected=!sender.selected;//每次点击都改变按钮的状态
    if (sender.selected == YES)
    {
        //        第一次点击为蓝色（关注）
        [sender setBackgroundImage:[UIImage imageNamed:@"stop"] forState:0];
        NSLog(@"已关注");
    }
    else
    {
        //        第二次点击为红色（如取消关注）
        [sender setBackgroundImage:[UIImage imageNamed:@"play"] forState:0];
        NSLog(@"取消关注");
    }
}
-(UIButton *)remove
{
    if (!_remove)
    {
        _remove =[[UIButton alloc]init];
        [_remove setBackgroundImage:[UIImage imageNamed:@"delete"] forState:0];


    }
    return _remove;
}

@end
